package net.lucamasini.ricette.server;

import static net.lucamasini.ricette.server.EntityManagerFactoryListener.jpaTemplateInContext;
import net.lucamasini.ricette.model.IngredientiRicetta;

import org.springframework.orm.jpa.JpaTemplate;

import com.google.gwt.requestfactory.server.RequestFactoryServlet;
import com.google.gwt.requestfactory.shared.Locator;

public class IngredientiRicettaLocator extends Locator<IngredientiRicetta, String> {

	private final JpaTemplate template;
	
	public IngredientiRicettaLocator() {
		super();

		template = jpaTemplateInContext(RequestFactoryServlet.getThreadLocalRequest().getSession(true).getServletContext());
	}

	@Override
	public IngredientiRicetta create(Class<? extends IngredientiRicetta> clazz) {
		return new IngredientiRicetta();
	}

	@Override
	public IngredientiRicetta find(Class<? extends IngredientiRicetta> clazz, String id) {
		return template.find(clazz, id);
	}

	@Override
	public Class<IngredientiRicetta> getDomainType() {
		return IngredientiRicetta.class;
	}

	@Override
	public String getId(IngredientiRicetta domainObject) {
		return domainObject.getId();
	}

	@Override
	public Class<String> getIdType() {
		return String.class;
	}

	@Override
	public Object getVersion(IngredientiRicetta domainObject) {
		return domainObject.getVersion();
	}

}
